package cn.edu.cqvie.netty.thrift;

import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import thrift.genrated.Person;
import thrift.genrated.PersonService;

public class ThriftClient {

    public static void main(String[] args) {
        TTransport transport = new TFramedTransport(new TSocket("127.0.0.1",8899), 600);

        TProtocol protocol = new TCompactProtocol(transport);

        PersonService.Client client = new PersonService.Client(protocol);
        try {
            transport.open();

            Person person = client.getPersonByUsername("zhengsh");
            System.out.println("person.name    =" +person.name);
            System.out.println("person.age     =" +person.age);
            System.out.println("person.married =" +person.married);

            Person person1 = new Person();
            person1.name     = "cqvie.edu.cn";
            person1.age      = 23;
            person1.married  = false;
            client.savePerson(person1);

        } catch (Throwable t) {
            throw  new RuntimeException(t.getMessage(), t);
        } finally {
            transport.close();
        }
    }
}
